using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library;
using NCS.Library.Components.Portal;
using NCS.Library.Components.Security;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Zones;

namespace NCS.Module.CMS.Admin
{
    public partial class SPSettings : AuthenticatedControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dropTheThao.DataSource = PortalController.GetPortalsByLang(AppEnv.GetLanguage());
                dropTheThao.DataBind();
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            //the thao
            drophothome.Items.Clear();
            dropTinTuc.Items.Clear();
            dropBongDa.Items.Clear();
            dropTheThaoDinhCao.Items.Clear();
            dropPhiaSauHauTruong.Items.Clear();
            dropGalleryAndClip.Items.Clear();
         
            //
            dropSPTinTuc.Items.Clear();
            dropSP_TinTuc_Position1.Items.Clear();

            dropSPBongDa.Items.Clear();
            dropSP_BongDa_Position1.Items.Clear();

            dropSPTheThaoDinhCao.Items.Clear();
            dropSP_TheThaoDinhCao_Position1.Items.Clear();

            dropSPPhiaSauHauTruong.Items.Clear();
            dropSP_PhiaSauHauTruong_Position1.Items.Clear();

            dropSPGalleryAndClip.Items.Clear();
            dropSP_GalleryAndClip_Position1.Items.Clear();
            
            //the thao
            int psp = ConvertUtility.ToInt32(Portal[Constants.CMS_PortalSP + AppEnv.GetLanguage()]);
            if (psp > 0)
            {
                MiscUtility.SelectItemFromList(dropTheThao, psp.ToString());
            }
            else
            {
                MiscUtility.SelectItemFromList(dropTheThao, ConvertUtility.ToString(Request.QueryString["portalid"]));
            }
                    
            ZoneController.LoadZones(drophothome.Items, dropTheThao.SelectedValue);

            foreach (ListItem item in drophothome.Items)
            {
                dropTinTuc.Items.Add(new ListItem(item.Text, item.Value));
                dropBongDa.Items.Add(new ListItem(item.Text, item.Value));
                dropTheThaoDinhCao.Items.Add(new ListItem(item.Text, item.Value));
                dropPhiaSauHauTruong.Items.Add(new ListItem(item.Text, item.Value));
                dropGalleryAndClip.Items.Add(new ListItem(item.Text, item.Value));

                //trang cap 2 va chi tiet
                dropSPTinTuc.Items.Add(new ListItem(item.Text, item.Value));
                dropSP_TinTuc_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropSPBongDa.Items.Add(new ListItem(item.Text, item.Value));
                dropSP_BongDa_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropSPTheThaoDinhCao.Items.Add(new ListItem(item.Text, item.Value));
                dropSP_TheThaoDinhCao_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropSPPhiaSauHauTruong.Items.Add(new ListItem(item.Text, item.Value));
                dropSP_PhiaSauHauTruong_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropSPGalleryAndClip.Items.Add(new ListItem(item.Text, item.Value));
                dropSP_GalleryAndClip_Position1.Items.Add(new ListItem(item.Text, item.Value));
            }

            int SP_hothome = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_TinNong + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(drophothome, SP_hothome.ToString());

            int SP_TinTuc = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_TinTuc + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTinTuc, SP_TinTuc.ToString());

            int SP_BongDa = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_BongDa + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropBongDa, SP_BongDa.ToString());

            int SP_TheThaoDinhCao = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_TheThaoDinhCao + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTheThaoDinhCao, SP_TheThaoDinhCao.ToString());

            int SP_PhiaSauHauTruong = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_PhiaSauHauTruong + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropPhiaSauHauTruong, SP_PhiaSauHauTruong.ToString());

            int SP_GalleryAndClip = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_GalleryAndClip + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropGalleryAndClip, SP_GalleryAndClip.ToString());

            //trang cap 2 va chi tiet

            // tin tuc
            int Level2_SP_TinTuc = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_SP_TinTuc + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSPTinTuc, Level2_SP_TinTuc.ToString());

            int CMS_Level2_TinTuc_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + Level2_SP_TinTuc + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSP_TinTuc_Position1, CMS_Level2_TinTuc_Position1.ToString());

            //tin bong da
            int Level2_SP_BongDa = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_SP_BongDa + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSPBongDa, Level2_SP_BongDa.ToString());

            int CMS_Level2_BongDa_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + Level2_SP_BongDa + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSP_BongDa_Position1, CMS_Level2_BongDa_Position1.ToString());

            //the thao din hcao
            int CMS_Level2_TheTheoDinhCao = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_SP_TheThaoDinhCao + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSPTheThaoDinhCao, CMS_Level2_TheTheoDinhCao.ToString());

            int CMS_Level2_TheThaoDinhCao_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_TheTheoDinhCao + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSP_TheThaoDinhCao_Position1, CMS_Level2_TheThaoDinhCao_Position1.ToString());

            //phia sau hau truong
            int CMS_Level2_SP_PhiaSauHauTruong = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_SP_PhiaSauHauTruong + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSPPhiaSauHauTruong, CMS_Level2_SP_PhiaSauHauTruong.ToString());

            int CMS_Level2_PhiaSauHauTruong_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_SP_PhiaSauHauTruong + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSP_PhiaSauHauTruong_Position1, CMS_Level2_PhiaSauHauTruong_Position1.ToString());

            //gallery and clip
            int CMS_Level2_SP_GalleryAndClip = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_SP_GalleryAndClip + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSPGalleryAndClip, CMS_Level2_SP_GalleryAndClip.ToString());

            int CMS_Level2_GalleryAndClip_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_SP_GalleryAndClip + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropSP_GalleryAndClip_Position1, CMS_Level2_GalleryAndClip_Position1.ToString());

        }
       
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                PortalSetting.SetValue(Constants.CMS_PortalSP + AppEnv.GetLanguage(), dropTheThao.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_SP_TinNong + AppEnv.GetLanguage(), drophothome.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_SP_TinTuc + AppEnv.GetLanguage(), dropTinTuc.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_SP_BongDa + AppEnv.GetLanguage(), dropBongDa.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_SP_TheThaoDinhCao + AppEnv.GetLanguage(), dropTheThaoDinhCao.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_SP_PhiaSauHauTruong + AppEnv.GetLanguage(), dropPhiaSauHauTruong.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_SP_GalleryAndClip + AppEnv.GetLanguage(), dropGalleryAndClip.SelectedValue);

                //trang cap 2 va chi tiet
                PortalSetting.SetValue(Constants.CMS_Level2_SP_TinTuc + AppEnv.GetLanguage(), dropSPTinTuc.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropSPTinTuc.SelectedValue + "_" + AppEnv.GetLanguage(), dropSP_TinTuc_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_SP_BongDa + AppEnv.GetLanguage(), dropBongDa.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropBongDa.SelectedValue + "_" + AppEnv.GetLanguage(), dropSP_BongDa_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_SP_TheThaoDinhCao + AppEnv.GetLanguage(), dropSPTheThaoDinhCao.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropSPTheThaoDinhCao.SelectedValue + "_" + AppEnv.GetLanguage(), dropSP_TheThaoDinhCao_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_SP_PhiaSauHauTruong + AppEnv.GetLanguage(), dropSPPhiaSauHauTruong.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropSPPhiaSauHauTruong.SelectedValue + "_" + AppEnv.GetLanguage(), dropSP_PhiaSauHauTruong_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_SP_GalleryAndClip + AppEnv.GetLanguage(), dropSPGalleryAndClip.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropSPGalleryAndClip.SelectedValue + "_" + AppEnv.GetLanguage(), dropSP_GalleryAndClip_Position1.SelectedValue);

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

      
    }
}